<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加减计数器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
        }
        .counter {
            font-size: 2em;
            margin: 20px 0;
        }
        button {
            font-size: 1em;
            padding: 10px 20px;
            margin: 0 10px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div>
        <button id="decrement">-</button>
        <span id="counter" class="counter">0</span>
        <button id="increment">+</button>
    </div>

    <script>
        // 获取页面元素
        const counterElement = document.getElementById('counter');
        const incrementButton = document.getElementById('increment');
        const decrementButton = document.getElementById('decrement');

        // 初始化计数器
        let counter = 0;

        // 增加计数器
        incrementButton.addEventListener('click', () => {
            counter += 1;
            counterElement.textContent = counter;
        });

        // 减少计数器
        decrementButton.addEventListener('click', () => {
            counter -= 1;
            counterElement.textContent = counter;
        });
    </script>
</body>
</html>